<template>
	<view class="pagesTop">
		<view class="top-containers">
			<view class="image-containers">
			    <u-swiper v-if="bannerArr.length>0" :list="bannerArr" keyName="image" height="230rpx" :radius="10" indicator indicatorMode='dot' @click="clickSwiper"></u-swiper>
			    <u--image v-else :src="image" width="100%" height="230rpx" :radius="10"></u--image>
			</view>
		</view>
		<view class="btn" @click="goLogin" v-if="isLoginStatus">
			<u-button type="primary" size="mini" icon='home-fill'>登出</u-button>
		</view>
		<view class="btn" @click="goLogin" v-else>
			<u-button type="primary" size="mini" icon='reload'>刷新</u-button>
		</view>
		<view class="btnb" @click="goEditPassword" v-if="isLoginStatus">
			<u-button type="primary" size="mini" icon='lock'>修改密码</u-button>
		</view>
		
	</view>
</template>

<script>
	import {
		getToken
	} from '@/utils/auth'
	import {
		findAllFrontHomePage
	} from '@/api/platform/FrontHomePage.js'
	export default {
		name:"pagesTop",
		data() {
			return {
				isLoginStatus:false,
				// baseUrl:getApp().globalData.config.baseUrl, //获取基础地址
				bannerArr:[],
				image:'/static/images/index/banner01.png',
				
			};
		},
		created(){
			// this.getDeptInfo()
			this.findAllFrontHomePage()
		},
		mounted() {
			if(getToken()){
				this.isLoginStatus=true
			}else{
				this.isLoginStatus=false
			}
		},
		methods:{
			clickSwiper(){
				
			},
			goEditPassword(){
				uni.navigateTo({
					url:'/subPackages/my/editPassword/editPassword'
				})
			},
			goLogin(){
				const timestamp = new Date().getTime();
				// 获取当前页面的实例
				const pages = getCurrentPages();
				const currentPage = pages[pages.length - 1];
				// 获取页面路径
				const pagePath = currentPage.route;
				console.log(pagePath)
				if(this.isLoginStatus){
					this.$store.dispatch('LogOut').then(res => {
					  uni.reLaunch({ url: `/pages/login/login}` })
					  
					})
				}else{
					uni.reLaunch({ url: `/?timestamp=${timestamp}` })
				}
				
			},
			findAllFrontHomePage(){
				findAllFrontHomePage().then(res=>{
					if(res.code==200){
						if(res.data[0].frontBanner){
							this.bannerArr=JSON.parse(res.data[0].frontBanner)
						}
						
					}

				})
			},
			getDeptInfo(){
				this.bannerArr=[
					'/static/images/index/banner01.png',
					'/static/images/index/banner02.png'
				]
			}
		}
	}
</script>

<style lang="scss" scoped>
	.pagesTop{
		position: relative;
		padding-top:16rpx;
		padding-bottom:16rpx;
		.btn{
			position: absolute;
			width: 140rpx;
			top: 16rpx;
			right: 0;
		}
		.btnb{
			position: absolute;
			// width: 160rpx;
			top: 16rpx;
			left: 0;
		}
	}

</style>